{include file="common/head_exit"}
<style>

</style>

<body style="background:#f3f5f7">
    {volist name="list" id="vo"}
    <center>
        <div class="title">
            {$vo.page_title}
        </div>
    </center>
    <input type="hidden" id="page_id" value="{$vo.page_id}">
    <div class="user_post">
        <div class="user_body">
            <div class="user_head">
                <img src="/meetTWO/public/static/picture/userHeadImg/{$vo.Number}/img.png" onerror="javascript:this.src='/meetTWO/public/static/picture/defaultHead.jpg';" alt="">
                <div class="user_sign">
                    <span>{$vo.user}</span>
                    <br>
                    <span class="user_time">{$vo.page_time}</span>
                </div>
            </div>
            <div class="user_text">
                {$vo.page_content}
            </div>
            <div class="user_foot">
                <div class="li-info user_span">
                    <span class="glyphicon glyphicon-comment" id="comments">{$vo.comment_num}</span>
                    <span class="glyphicon glyphicon-eye-open" id="view_num">{$vo.view_num}</span>
                    <span class="glyphicon glyphicon-heart content" id="content">{$vo.content}</span>
                </div>
            </div>
        </div>
    </div>
    {/volist}
    <!-- 評論 -->

    {volist name="comment" id="vo"}
    <div class="user_body_l" name="comment">
        <div class="user_head_l">
            <img src="/meetTWO/public/static/picture/userHeadImg/{$vo.Number}/img.png" onerror="javascript:this.src='/meetTWO/public/static/picture/defaultHead.jpg';" alt="">
            <div class="user_sign_l">
                <span>{$vo.user}</span>
                <br>
                <span class="user_time_l">{$vo.comment_time}</span>
            </div>
        </div>
        <br />
        <br />
        <div class="user_text_l">
            {$vo.comment_content}
        </div>
    </div>
    {/volist}
    <div id="linshi"></div>
    <br />
    <br />
    <br />

    <div class="col-lg-12 post1" style="width:100%;">
        <div class="input-group post2">
            <input type="text" class="form-control" id="comment" placeholder="输入你想评论的内容">
            <span class="input-group-btn">
                <button class="btn btn-default" id="commit_submmit" type="button">发送</button>
            </span>
        </div>
    </div>
</body>
<script>
    //评论发布
    $("#commit_submmit").click(function() {
        $.get('/meetTWO/public/index/circle/addcomment', {
            comment: $('#comment')[0].value,
            id: getCookie('number'),
            page_id: $('#page_id')[0].value
        }, function(data) {
            if (data == 1) {
                console.log("评论发表成功");
                var text = $("#comment").val();
                var date = new Date();
                $.get('/meetTWO/public/index/circle/user_name', {
                    id: getCookie('number')
                }, function(e) {
                    $('#linshi').append(`<div class="user_body_l" name="comment">
        <div class="user_head_l">
            <img src="/meetTWO/public/static/picture/userHeadImg/` + getCookie('number') + `/img.png" onerror="javascript:this.src='/meetTWO/public/static/picture/defaultHead.jpg';"
                alt="">
            <div class="user_sign_l">
                <span>` + e[0].user + `</span>
                <br>
                <span class="user_time_l">` + date.toLocaleTimeString() + `</span>
            </div>
        </div>
        <div class="user_text_l">` +
                        text + `
        </div>
    </div>`)
                })
                var com = $('#comments').text();
                $('#comments').text("");
                com = parseInt(com) + 1;
                $('#comments').append(com)
                $("#comment").val("").focus();
            } else {
                alert("网络错误")
            }
        })
        console.log($('#comment')[0].value)
    })



    function getCookie(name) {
        var strcookie = document.cookie; //获取cookie字符串
        var arrcookie = strcookie.split("; "); //分割
        //遍历匹配
        for (var i = 0; i < arrcookie.length; i++) {
            var arr = arrcookie[i].split("=");
            if (arr[0] == name) {
                return arr[1];
            }
        }
        return "";
    }
    var a = 0;
    // 浏览次数
    $(document).ready(function() {
            // $("#content").css("color","red");
            var view_num = Number($("#view_num").html());
            view_num = view_num + 1;
            $("#view_num").html(" " + view_num);
            var url = location.search; //获取url中"?"符后的字串   
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            a = theRequest.data;
            console.log(a);
            $.get('/meetTWO/public/index.php/index/circle/comment_num', {
                num: a
            }, function(d) {
                console.log(d)
            })
            $.get('/meetTWO/public/index.php/index/circle/view_num', {
                numb: a
            }, function(d) {
                console.log(d)
            })
            var user_name = document.cookie.substring(7);
            var content = Number($("#content").html());
            $.get('/meetTWO/public/index.php/index/circle/status', {
                numb: a,
                user_name: user_name
            }, function(x) {
                console.log(x);
                if (x == 1) {
                    $("#content").css("color", "red");
                }
            })
        })
        //小心心
    $("#content").click(function() {
        var user_name = document.cookie.substring(7);
        var content = Number($("#content").html());
        $.get('/meetTWO/public/index.php/index/circle/status', {
            numb: a,
            user_name: user_name
        }, function(x) {
            x == 0 ? x = 1 : x = 0;
            if (x == 1) {
                $("#content").css("color", "red");
                content = content + 1;
                $("#content").html(" " + content);
            } else {
                $("#content").css("color", "#bccbd5");
                if (content != 0) {
                    content = content - 1;
                    $("#content").html(" " + content);
                }
            }

            $.get('/meetTWO/public/index.php/index/circle/content', {
                numb: a,
                sta: x,
                user_name: user_name
            }, function(x) {
                console.log(x)
            })
        })
    })
</script>